package systemfnomabss



trait Interpreter{ self: Interpreter with Evaluator with TypeChecker 
                         with PrettyPrinter  
                         with TextToAbstractSTParser
                         with AbstractSyntax =>

  val verbose:Boolean  
  
  
  //type rawterm = concretesyntax.LTerm
  //type Node = LTerm
  def eval(line: String):LTerm = {
      val canontree=parse(line);
      typeCheck(canontree); //throws typeExc so we only eval if type is ok
      eval(canontree);
  }
  def interpret(line:String):String = {
      val canontree = parse(line)
      typeCheck(canontree) //throws typeException if no valid type
      val result = eval(canontree)
      prettyPrint(result)
  }
  
  def parse(line: String):LTerm = {
    if (verbose)   println("srccode = "+ line)
    val canontree = parseToAST(line) getOrElse exit(1)
    if (verbose) { println("   parse= " + prettyPrint(canontree))
                   println("   AST  = " + canontree.toString)
                 }
    canontree
  }
  
  
  
  
  def typeCheck(canontree: LTerm):LType =  {
  
    val ty = typeOf(canontree)
    if (verbose) println("       :: "+prettyPrint(ty))
    ty
  }
  
  def eval(canontree: LTerm):LTerm =  {
    val value = evaluate(canontree)
    if (verbose) println(" =======> " + prettyPrint(value))
    value
  }
}








